/*
 * Created by Dev c++ 5.11
 * Author: liyih
 * Date: 2018/03/16
 */

#include <iostream>
using namespace std;
int main()
{
	int n, p[500];
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>p[i];
	}
	for(int i = n-1; i >= 1; i--){
		if(p[i]  <= p[0])cout<<p[i]<<" ";
	}
	cout<<p[0]<<" ";
	for(int i = 1; i < n; i++){
		if(p[i] > p[0])cout<<p[i]<<" ";
	}
	return 0;
}
